{extend name='public/base' /}

{block name="content"}
<style type="text/css">
	.layui-form-pane .layui-form-label {
	    overflow: initial !important;
	}
    .tanchu {
        position: absolute;
        top: 170px;
        left: 440px;
        background-color: #fff;
        border: #ccc solid 1px;
        width: 1000px;
        border-radius: 10px;
    }
</style>
<div class="layui-col-md12">
    <div class="layui-card">
        <div class="layui-card-body">
            <form action="" class="layui-form" method="get">
                <div class="layui-form-item layui-form-pane">
<!--                    <div class="layui-inline">-->
<!--                        <label class="layui-form-label">关联订单号：</label>-->
<!--                        <div class="layui-input-inline">-->
<!--                            <input name="order_sn" class="layui-input" id="title" value="" type="text"-->
<!--                                   placeholder="请输入关联订单号">-->
<!--                        </div>-->
<!--                    </div>-->
                    <div class="layui-inline">
                        <label class="layui-form-label">商户：</label>
                        <div class="layui-input-inline">
                            <select name="merchant_id" lay-verify="required" lay-search="">
                                <option value="0" ></option>
                                {volist name="merchant_list" id="t"}
                                {if empty($t.name)||$t.name=='-'}
                                <option value="{$t.id}" >{$t.company} - {$t.code}-{$t.biz_state}-{$t.positions_code}</option>
                                {else/}
                                <option value="{$t.id}" >{$t.name} - {$t.code}-{$t.biz_state}-{$t.positions_code}</option>
                                {/if}
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" style="overflow: inherit;">合同编号：</label>
                        <div class="layui-input-inline">
                            <input name="code" class="layui-input" id="code" value="" type="text"
                                   placeholder="合同编号">
                        </div>
                    </div>
                <!--    <div class="layui-inline">
                        <label class="layui-form-label">手机号码：</label>
                        <div class="layui-input-inline">
                            <input name="mobile" class="layui-input" id="mobile" value="" type="text"
                                   placeholder="请输入手机号码">
                        </div>
                    </div> -->
                    <div class="layui-inline">
                        <button class="layui-btn icon-btn layui-btn-sm" data-id="table_id" lay-filter="search"
                                lay-submit="">
                            <i class="layui-icon"></i>搜索
                        </button>
                        <button type="reset" class="layui-btn icon-btn layui-btn-normal layui-btn-sm"><i
                                class="layui-icon layui-icon-refresh"></i>{:__('Reset')}
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>


    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" id="table_id" lay-filter="table_id"></table>
        </div>
    </div>

</div>
{/block}

{block name="js"} <!--js处理区-->
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button type="button" id="export" class="layui-btn {:node('Balance/export')} layui-btn-sm">导出模板
        </button>
        <button type="button" id="import" class="layui-btn {:node('Balance/import')} layui-btn-sm">导入</button>
        <!-- <button type="button" id="import" class="layui-btn {:node('ExportCenter/import')} layui-btn-sm">导入</button> -->
    </div>
</script>
<script type="text/html" id="operationTpl">
    <a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs {:node('Balance/del')}" data-title="删除"
       lay-event="del"><i class="layui-icon "></i></a>
</script>
<script>
    layui.use(['element', 'table', 'form', 'jquery', 'lucky', 'opTable', 'upload'], function () {
        var element = layui.element;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;
        var lucky = layui.lucky;
        var upload = layui.upload;
        var opTable = layui.opTable;
        form.render();

        var myTables = table.render({
            elem: '#table_id',
            url: "{:url('index')}",
            toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
            // defaultToolbar: ['filter', 'exports', 'print'],
            defaultToolbar: ['filter',  'print'],
            even: true, //开启隔行背景
            id: 'table_id',
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip', 'last'] //自定义分页布局
                , groups: 5 //只显示 1 个连续页码
                , first: false //不显示首页
                , last: false //不显示尾页
                , limit: 20
                , limits: [10, 20, 30, 50]
            },
              // height: 'full-100',100',
            text: {
                none: '暂无相关数据'
            },
            cols: [[
                {title: 'id', field: 'id',width:90},
				{title: '品牌名称', field: 'merchant', templet: function (item) {
				        return item.name
				    }
				},
                {title: '签约公司', field: 'merchant', templet: function (item) {
                        return item.company
                    }
                },
                {title: '合同号', field: 'merchant', templet: function (item) {
                        return item.code
                    }
                },
                {title: '交易金额变动情况', field: 'edit',width:160, templet: function (item) {
                        return item.edit==1?'增加':'减少'
                }},
             
                {title: '交易金额（元）', field:'amount',templet: function (item) {
						 return item.amount/100
                }},
                {title: '类型', field: 'is_top_up',width:90,templet: function (item) {
                        if(item.is_top_up==1){
                            return '充值'
                        }else if(item.is_top_up==2){
                            return '缴费'
                        }else if(item.is_top_up==4){
                            return '线上转入'
                        }else if(item.is_top_up==5){
                            return '退费'
                        }else {
                            return '余额缴费'
                        }

                        // return item.is_top_up==1?'充值':(item.is_top_up==2? '缴费':(item.is_top_up==4? '线上转入':'退押金'))
                }},
                {title: '交易类型', field: 'is_top_up',width:90,templet: function (item) {
                    if(item.type==1){
                        return '线上充值'
                    }else if(item.type==2){
                        return '转账'
                    }else {
                        return '余额缴费'
                    }
                    }},
				 // {title: '关联订单号', field: 'order_sn'},
                 {title: '交易时间', field: 'create_time'},
                {title: '备注', field:'remark'},
                {templet: '#operationTpl', width:50,fixed:'right', align: 'center', title: '操作'}
            ]],
            //  展开的列配置
            openCols: [
                {field: 'desc', title: '描述信息'}
            ],
            done: function (res) {
                layer.closeAll('loading');
            }
        });
        //导出
        $('#export').on('click', function () {
            var url = "{:url('export')}";
            window.open(url);
        });
        //导入
        upload.render({
            elem: '#import',
            url: "{:url('import')}",
            accept: 'file', //普通文件
            multiple: false,
            exts: 'xlsx|xls', // 限制文件类型为 xlsx或xls
            done: function (data) {  // 成功的回调函数
                console.log(data)
                if(data.code==1){
                    alert(data.msg);
                }
            }
            , error: function (index, upload) {  // 失败的回调函数

            }
        });
        //导出时阻止页面刷新
        $(".layui-form").submit(function (e) {
            e.preventDefault();
        })

        /**
         * 监听单行工具操作
         */
        table.on('tool(table_id)', function (obj) {
            var data = obj.data;
            var _id = parseInt(data.id);
            var layEvent = obj.event;
            if (layEvent === "edit") {
                var urls = "{:url('add')}?id=" + _id;
                lucky.CreateOpenForm("编辑", urls);

            } else if (layEvent === "del") {
                lucky.FormatData(_id, "{:url('del')}");
            }
        });


        table.on('toolbar(table_id)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            if (obj.event === "add") {
                lucky.CreateOpenForm("添加","{:url('add')}");
                return false;
            } else if (obj.event === "close") {
                opTables.closeAll();
            } else if (obj.event === "open") {
                opTables.openAll();
            } else if (obj.event === "reload") {
                lucky.CreateReload();
            } else if (obj.event === "del") {
                var num = 0;
                var id = [];
                for (var i in data) {
                    num++;
                    id.push(data[i].id);
                }
                if (num < 1) {
                    layer.msg("请选择一项", {time: 1500});
                    return false;
                }
                lucky.FormatData(id, "{:url('del')}");
                return false;
            }
        });

        /**
         * 关键词搜索树
         */
        form.on('submit(search)', function (obj) {
            lucky.CreateSearch(obj.field);
            return false;
        });
    });

</script>

{/block}
